<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Validform/5.3.2/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css"/>
    <title>添加按钮</title>
</head>
<body>
<div class="pd-30 roledescribtion_add">
    <form id="role_form" action="">
        <div class="row cl mb-20">
            <label class="form-label col-sm-2 text-r"><span class="c-red">*</span>按钮名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="ROLE_NAME" name="ROLE_NAME">
            </div>
        </div>
        <div class="row cl mb-20">
            <div class="form-label col-sm-2 text-r">状态：</div>
            <div class="formControls col-xs-8 col-sm-9"><input type="checkbox" checked="checked" class="checkBox valid"
                                                               value="" id="checkboxName" name="checkboxName"><span
                    class="ml-10">启用</span></div>
        </div>

        <div class="text-c pd-20">
            <button class="btn btn-secondary radius" href="##" type="submit">确定</button>
            <button class="btn radius ml-10" href="##" type="button" onclick="role_close()">取消</button>
        </div>
    </form>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript">
    function role_close() {
        var index = parent.location.reload();
        parent.layer.close(index);
    }

    $(function () {
        var editData = JSON.parse(window.session_storage.getItem('ROLE_editData'));
        if (editData.ROLE_ISEIDT == true) {
            $('#ROLE_NAME').val(editData.buttonName);
            if (editData.status == 0) {
                $("#checkboxName").prop("checked", true)
            } else {
                $("#checkboxName").prop("checked", false)
            }
            $("#role_form").validate({
                rules: {
                    ROLE_NAME: {
                        required: true,
                        minlength: 1,
                        maxlength: 20
                    },
                    DESCRIPTION: {
                        minlength: 1,
                        maxlength: 50
                    }
                },
                submitHandler: function (form) {
                    console.log(11);
                    var status;
                    if ($("#checkboxName")[0].checked == true) {
                        status = 0;
                    } else {
                        status = 1;
                    }
                    $.ajax({
                        type: "POST",
                        url: root.accessInter.access_button_update,
                        cache: false,  //禁用缓存
                        dataType: "json",
                        data: {
                            buttonId: editData.buttonId,
                            buttonName: $('#ROLE_NAME').val(),
                            buttonStatus: status
                        },  //传入组装的参数
                        success: function (data) {
                            if (data.errorCode == 0) {
                                layer.msg("保存成功!", {icon: 1, time: 1000});
                                var index = parent.location.reload();
                                parent.layer.close(index);
                            } else {
                                layer.msg(data.errorMessage, {icon: 1, time: 1000});
                            }
                        },
                    })
                }
            });
        } else {
            $("#role_form").validate({
                rules: {
                    ROLE_NAME: {
                        required: true,
                        minlength: 2,
                        maxlength: 20
                    },
                    DESCRIPTION: {
                        minlength: 2,
                        maxlength: 50
                    }
                },
                submitHandler: function (form) {
                    var status;
                    if ($("#checkboxName")[0].checked == true) {
                        status = 0;
                    } else {
                        status = 1;
                    }
                    $.ajax({
                        type: "POST",
                        url: root.accessInter.access_button_add,
                        cache: false,  //禁用缓存
                        dataType: "json",
                        data: {
                            buttonName: $('#ROLE_NAME').val(),
                            buttonStatus: status
                        },  //传入组装的参数
                        success: function (data) {
                            if (data.errorCode == 0) {
                                layer.msg("保存成功!", {icon: 1, time: 1000});
                                var index = parent.location.reload();
                                parent.layer.close(index);
                            } else {
                                layer.msg("系统服务异常!", {icon: 1, time: 1000});
                            }
                        },

                    })
                }
            });
        }
    });

</script>
</body>
</html>